package com.fs.groupSeven.service.impl;

import com.fs.groupSeven.Dao.TeacherDao;
import com.fs.groupSeven.pojo.College;
import com.fs.groupSeven.pojo.Teacher;
import com.fs.groupSeven.service.TeacherService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @description:
 * @author： mjx
 * @createDate: 2020/10/9
 * @version: 1.0
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired//自动装配 依赖注入
    private TeacherDao teacherDao;

    public TeacherServiceImpl(TeacherDao teacherDao) {
        this.teacherDao = teacherDao;
    }

    @Override
    public PageInfo<Teacher> getListByPageAndTeacherName(Integer currentPage, Integer pageSize, String teacherName) {
        //准备拦截mybatis的后续查询
        List<Teacher> teacherList;
        PageHelper.startPage(currentPage,pageSize);
        teacherList = teacherDao.queryByColumn(teacherName);
        //pagehelper内部帮我们计算总共有多少页
        PageInfo<Teacher> pageInfo = new PageInfo<>(teacherList);
        return pageInfo;
    }

    @Override
    public boolean addOneTeacher(Teacher teacher) {
        int  result =  teacherDao.insertTeacher(teacher);
        return result>0;
    }

    @Override
    public boolean removeOneTeacher(Teacher teacher) {
        int result = teacherDao.deleteByTeacher(teacher);
        return result>0;
    }

    @Override
    public boolean modifyOneTeacher(Teacher teacher) {
        int result = teacherDao.updateByTeacher(teacher);
        return result >0;
    }

    @Override
    public List<College> getCollegelist() {
        List<College> colleges = teacherDao.queryCollegeList();
        return colleges;
    }

    @Override
    public Teacher getOneByTeacherId(Integer teacherId) {
        return teacherDao.queryOneByTeacherId(teacherId);
    }

    @Override
    public PageInfo<Teacher> getTeachersByPage(Integer currentPage, Integer pageSize) {
        //准备拦截mybatis的后续查询
        List<Teacher> teacherList;
        PageHelper.startPage(currentPage,pageSize);
        teacherList = teacherDao.queryTeacherList();
        //pagehelper内部帮我们计算总共有多少页
        PageInfo<Teacher> pageInfo = new PageInfo<>(teacherList);
        return pageInfo;
    }
}
